package leetcode;

import java.util.Collections;
import java.util.List;

public class _2824 {
    /**
     * 统计和小于目标的下标对数目
     */
    class Solution {
        public int countPairs(List<Integer> nums, int target) {
            int n = nums.size();
            int ans = 0;
            int left =0,right = n-1;
            Collections.sort(nums);
            while(left<right){
                if(nums.get(left)+nums.get(right)<target){
                    ans +=right-left;
                    left++;
                }else{
                    right--;
                }
            }
            return ans;
        }
    }
}
